package com.gnerv.battle.boot.module.base.controller;

import com.gnerv.battle.boot.common.base.model.RestResult;
import com.gnerv.battle.boot.module.base.business.NoticeBusiness;
import com.gnerv.battle.boot.module.base.model.dto.NoticeCreateDTO;
import com.gnerv.battle.boot.module.base.model.dto.NoticeDTO;
import com.gnerv.battle.boot.module.base.model.dto.NoticeReceiveDTO;
import com.gnerv.battle.boot.module.base.model.dto.NoticeUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/manage/notice")
public class NoticeController {

    private final NoticeBusiness noticeBusiness;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody NoticeCreateDTO noticeCreateDTO) {
        return noticeBusiness.create(noticeCreateDTO);
    }

    @PostMapping(value = "/send")
    public RestResult<Void> send(@RequestBody NoticeReceiveDTO noticeReceiveDTO) {
        return noticeBusiness.send(noticeReceiveDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return noticeBusiness.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody NoticeUpdateDTO noticeUpdateDTO) {
        return noticeBusiness.updateByUkId(noticeUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<NoticeDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return noticeBusiness.selectByUkId(ukId);
    }

    @GetMapping(value = "list/title")
    public RestResult<List<NoticeDTO>> listByTitle(@RequestParam(required = false, value = "title") String title,
                                                   @RequestParam(value = "page") Integer page,
                                                   @RequestParam(value = "size") Integer size) {
        return noticeBusiness.listByTitle(title, page, size);
    }

    @GetMapping(value = "list/account")
    public RestResult<List<NoticeDTO>> listByAccountUkId(@RequestParam(value = "accountUkId") String accountUkId,
                                                         @RequestParam(value = "page") Integer page,
                                                         @RequestParam(value = "size") Integer size) {
        return noticeBusiness.listByAccountUkId(accountUkId, page, size);
    }

    @GetMapping(value = "receive")
    public RestResult<NoticeDTO> selectReceiveByNoticeUkId(@RequestParam(value = "noticeUkId") String noticeUkId) {
        return noticeBusiness.selectReceiveByNoticeUkId(noticeUkId);
    }

    @GetMapping(value = "receive/list")
    public RestResult<List<NoticeDTO>> listReceive(@RequestParam(required = false, value = "status") String status,
                                                   @RequestParam(value = "page") Integer page,
                                                   @RequestParam(value = "size") Integer size) {
        return noticeBusiness.listReceive(status, page, size);
    }

}
